package tech.aistar.day02;

import java.sql.SQLOutput;
import java.util.Arrays;

/**
 * 本类用来演示: 二维数组练习
 *
 * @author: success
 * @date: 2022/7/19 2:38 下午
 */
public class TwoArrayDemo {
    public static void main(String[] args) {
        //printArr();

        int[] arr1 = {1,2,3};
        int[] arr2 = {1,2,3};
        System.out.println(arr1);
        System.out.println(arr2);
        System.out.println(arr1 == arr2);//false

        //数组值的比较
        System.out.println(Arrays.equals(arr1, arr2));//true

        char[] c = {'a','b','c'};
        System.out.println(c);//abc  字符串的本质就是字符数组

        String[][] arr = {{"白","日","依","山","尽"},{"黄","河","入","海","流"},{"欲","穷","千","里","目"},{"更","上","一","层","楼"}};

        poemMath(arr);

    }

    public static void printArr(){
        int[][] arr = {{1,2,3},{3,4,5},{5,6,7}};
        //for (int i = 0; i < arr.length; i++) {
        //    for (int j = 0; j < arr[i].length; j++) {
        //        System.out.print(arr[i][j]+"\t");
        //    }
        //    System.out.println();
        //}

        System.out.println(Arrays.deepToString(arr));
    }

    public static void poem(String[][] arr){
        //定义一个新的数组-竖着的
        String[][] temp = new String[arr[0].length][arr.length];

        //遍历arr
        for (int i = 0; i < arr.length; i++) {
            for (int j = 0; j < arr[i].length; j++) {
                temp[j][i] = arr[i][j];
            }
        }

        //遍历temp
        //System.out.println(Arrays.deepToString(temp));

        for (int i = 0; i < temp.length; i++) {
            for (int j = 0; j < temp[i].length; j++) {
                System.out.print(temp[i][j]);
            }
            System.out.println();
        }
    }

    public static void poemMath(String[][] arr){
        //所有的数据放入到一维数组中.
        String[] temp = new String[arr[0].length*arr.length];

        //下标计数器
        int pos = 0;

        for (int i = 0; i < arr.length; i++) {
            for (int j = 0; j < arr[i].length; j++) {
               temp[pos++]  = arr[i][j];
            }
        }
        //白, 日, 依, 山, 尽, 黄, 河, 入, 海, 流, 欲, 穷, 千, 里, 目, 更, 上, 一, 层, 楼
        //白黄欲更  第一行  0   5    10   15
        //日河穷上  第二行  1   6    11   16
        //System.out.println(Arrays.toString(temp));
        String[][] tt = new String[arr[0].length][arr.length];

        for (int i = 0; i < tt.length; i++) {
            for (int j = 0; j < tt[i].length; j++) {
                tt[i][j] = temp[5*j+i];
            }
        }

        for (int i = 0; i < tt.length; i++) {
            for (int j = 0; j < tt[i].length; j++) {
                System.out.print(tt[i][j]);
            }
            System.out.println();
        }
    }
}
